package com.itheima.Demo04;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

//使用lock锁;
public class AAA implements Runnable {
    //创建一个变量;
    int a = 100;
    //创建一个锁对象;
    Lock l = new ReentrantLock();


    @Override
    public void run() {
        while (true) {
            //加锁;
            l.lock();
            //判断;
            if (a <= 0) {
                //需要在这里再加一个解锁,不然程序没有办法停止;
                l.unlock();
                break;
            }
            System.out.println(Thread.currentThread().getName() + "售出了" + a + "号票");
            a--;
            //解锁;
            l.unlock();
        }
    }
}
